package com.wanxi.arraylist;

import java.util.ArrayList;

public class FindEighteen {
    public static void main(String[] args) {
        Student student1 = new Student("陈明", 27);
        Student student2 = new Student("王海云", 25);
        Student student3 = new Student("江黎", 28);
        Student student4 = new Student("江黎", 18);
        Student student5 = new Student("江", 17);

        //ArrayList<String> array = new ArrayList<String>();
        ArrayList<Student> studentArrayList = new ArrayList<Student>();

        studentArrayList.add(student1);
        studentArrayList.add(student2);
        studentArrayList.add(student3);
        studentArrayList.add(student4);
        studentArrayList.add(student5);

        ArrayList<Student> studentEighteen=getArraylist(studentArrayList);


    }

    private static ArrayList getArraylist(ArrayList<Student> studentArrayList) {
        ArrayList<Student> studentEighteen = new ArrayList<Student>();


        for (int i = 0; i < studentArrayList.size(); i++) {

            if(studentArrayList.get(i).getAge() <= 18){
                studentEighteen.add(studentArrayList.get(i));

            }

        }
        return studentEighteen;
    }


}
